package com.symria.framework.util;

import java.util.List;

import com.symria.framework.page.Page;
import com.symria.server.po.AuthInfo;
import com.symria.server.po.MenuInfo;

import net.sf.json.JSONObject;


public class JsonUtil {
	public static JSONObject createCheckMenu(List<MenuInfo> list){
		StringBuffer menuReg= new StringBuffer("");
		boolean b = true;
		for(MenuInfo menu:list){
			if(b){
				menuReg.append(menu.getId());
				b=false;
			}else{
				menuReg.append("|"+menu.getId());
			}
		}
		JSONObject obj = new JSONObject();
		obj.element("menuReg", menuReg.toString());
		return obj;
	}
	public static JSONObject createAuthInfo(List<AuthInfo> list){
		StringBuffer menuReg= new StringBuffer("");
		boolean b = true;
		for(AuthInfo au:list){
			if(b){
				menuReg.append(au.getId());
				b=false;
			}else{
				menuReg.append("|"+au.getId());
			}
		}
		JSONObject obj = new JSONObject();
		obj.element("menuReg", menuReg.toString());
		return obj;
	}
	public static JSONObject getPageFoot(Page page){
		JSONObject o = new JSONObject();
		    o.element("from", page.getStartRow());
		    o.element("currentPage", page.getCurrentPage());
		    o.element("size", page.getPageSize());
		    o.element("totalpage", page.getTotalPages());
		    o.element("totalrow", page.getTotalRows());
		return o;
	}
}
